
define([
], function (require, exports) {
    exports.ready = function (hashCode, data, cite) {
        // 注册该功能要用到的数据字典
        yufp.lookup.reg('DATA_STS,SYS_TYPE,TASK_STAT,YES_NO');
        // 创建virtual model
        yufp.custom.vue({
            el: '#GridCustomerAUMAndProductCompositionReport',
            // 以m_开头的属性为UI数据不作为业务数据，否则为业务数据
            data: function () {
                return {
                    // 导出查询进度事件间隔
                    delay: 2000,
                    // 导出进度查询定时器
                    progressTimer: false,
                    progressUrl: '/api/NetworkLiabilityStatementsResource/queryDownloadInfo',
                    GridCustomerAUMAndProductCompositionReportData:{condition: JSON.stringify({
                            userId: yufp.session.userId,
                            orgId: yufp.session.user.org.code,
                            roleId:yufp.session.user.roles[0].code,
                        })},
                    funcDataUrl:backend.msmFrontWebService + '/api/GridCustomerAUMAndProductCompositionReportResource/getGridCustomerAUMAndProductCompositionReportInfo',
                    loading: false,
                };
            },
            // 钩子
            mounted: function () {
            },
            methods: {
                exportExcel: function () {
                    var me = this;
                    me.loading = true;
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/GridCustomerAUMAndProductCompositionReportResource/exportExcel',
                        method: 'GET',
                        data: me.GridCustomerAUMAndProductCompositionReportData,
                        callback: function (code, message, res) {
                            if (code != 0) {
                                me.$message.error(message);
                                return;
                            }
                            var taskId = res ? res.data : false;
                            if (taskId) {
                                me.taskId = taskId;
                                me.progressVisible = true;
                                me.progressTimer = setTimeout(me.showProgressFn(), me.delay);
                            } else {
                                me.$message.error('导出失败！');
                            }
                        }
                    });
                },
                /**
                 * 轮询查询进度
                 * @param {String} taskId 任务ID
                 */
                showProgressFn: function () {
                    var vm = this;
                    yufp.service.request({
                        url: vm.progressUrl,
                        method: 'GET',
                        data: {
                            taskId: vm.taskId
                        },
                        callback: function (code, message, res) {
                            window.console.info('-----res-----');
                            window.console.info(res.data.percent);
                            if (code != 0) {
                                vm.$message.error(message);
                                return;
                            }
                            vm.percentage = res.data.percent;
                            if (res.data.percent < 100) {
                                vm.progressTimer = setTimeout(vm.showProgressFn, vm.delay);
                            } else {
                                vm.downloadFile();
                            }
                        }
                    });
                },
                downloadFile: function () {
                    var url = "";
                    url += yufp.settings.url;
                    url += '/' + backend.msmFrontWebService;
                    url += 'api/NetworkLiabilityStatementsResource/downloadDepExcel?' + 'taskId=' + this.taskId;
                    window.open(yufp.util.addTokenInfo(url));
                    this.loading = false;
                    this.exportVisible = false;
                    this.progressVisible = false;
                },
                searchFn: function () {
                    var me = this;
                    var param = {
                        condition: JSON.stringify({
                            gridName: me.$refs.GridCustomerAUMAndProductCompositionReportInfoSearch.formdata.gridName,
                            secondGridName: me.$refs.GridCustomerAUMAndProductCompositionReportInfoSearch.formdata.secondGridName,
                            userNo: me.$refs.GridCustomerAUMAndProductCompositionReportInfoSearch.formdata.userNo,
                            userName: me.$refs.GridCustomerAUMAndProductCompositionReportInfoSearch.formdata.userName,
                            etlDt:me.$refs.GridCustomerAUMAndProductCompositionReportInfoSearch.formdata.etlDt ==="" ? "" :  new Date(me.$refs.GridCustomerAUMAndProductCompositionReportInfoSearch.formdata.etlDt - 24*60*60*1000),
                        })
                    };
                    me.$refs.GridCustomerAUMAndProductCompositionReportTable.remoteData(param);
                },
                switchStatus: function (viewType, editable) {
                    var _this = this;
                    _this.dialogStatus = viewType;
                    _this.saveBtnShow = editable;
                    _this.dialogFormVisible = true;
                    _this.formDisabled = !editable;
                },
            }
        });
    };

    // 消息处理
    exports.onmessage = function (type, message) { };

    // page销毁时触发destroy方法
    exports.destroy = function (id, cite) {};
});
